package acm.蓝桥24;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.StringTokenizer;

/**
 * 牢底坐穿题
 */
public class G_内存占用 {
	public static void main(String[] args) {
		Reader sc = new Reader();
		int n = sc.nextInt();
		long sum = 0;
		for (int i = 0; i < n; i++) {
			char[] charArray = sc.nextLine().toCharArray();
			if(charArray.length==0) {
				i--;
				continue;
			}
			sum += handle(charArray);
		}
		System.out.println(fomat(sum));
	}

	public static boolean isArr(char[] str) {
		return str[str.length - 2] == ']';
	}

	public static long typeLen(char[] str) {
		return str[0] == 'i' ? 4 : 8;
	}

	public static boolean isString(char[] str) {
		return str[0] == 'S';
	}

	public static int indexOf(char[] str, char c, int i) {
		while (i < str.length && str[i] != c) {
			i++;
		}
		return i;
	}

	public static long argsCount(char[] str) {
		long cnt = 0;
		for (char c : str) {
			if (c == '=')
				cnt++;
		}
		return cnt;
	}


	public static String fomat(long sum) {
		StringBuilder build = new StringBuilder();
		String[] unit = { "GB", "MB", "KB", "B" };
		long[] size = { 1 << 30, 1 << 20, 1 << 10, 1 };
		for (int i = 0; i < size.length; i++) {
			if (sum / size[i] > 0) {
				build.append(sum / size[i]).append(unit[i]);
				sum %= size[i];
			}
		}
		return build.toString();
	}

	public static long handle(char[] str) {
		if (isArr(str)) {
			return handleArr(str);
		} else if (isString(str)) {
			return handleStr(str);
		} else {
			return handleArgs(str);
		}
	}

	public static long handleArgs(char[] str) {
		return typeLen(str) * argsCount(str);
	}

	public static long handleArr(char[] str) {
		long len = typeLen(str);
		int cur = indexOf(str, '=', 4);
		long sum = 0;
		while (str[cur] != ';') {
			int pre = indexOf(str, '[', cur);
			int suf = indexOf(str, ']', pre);
			long size = Long.parseLong(new String(str, pre + 1, suf-pre-1));
			sum += size * len;
			cur = suf + 1;
		}
		return sum;
	}

	public static long handleStr(char[] str) {
		int cur = 8;
		long sum = 0;
		char c=indexOf(str, '”', 0)!=str.length?'”':'"';
		while (str[cur] != ';') {
			int pre = indexOf(str, c, cur);
			int suf = indexOf(str, c, pre+1);
			cur = suf + 1;
			sum += suf - pre - 1;
		}
		return sum;
	}
	static class Reader {
	    private PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
	    private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
	    private StringTokenizer tokenizer = new StringTokenizer("");

	    private String innerNextLine() {
	        try {
	            return reader.readLine();
	        } catch (IOException ex) {
	            return null;
	        }
	    }

	    public boolean hasNext() {
	        while (!tokenizer.hasMoreTokens()) {    //内存中没有
	            String nextLine = innerNextLine();
	            if (nextLine == null) {     //且没有下一行
	                return false;
	            }
	            tokenizer = new StringTokenizer(nextLine);  //读入一行
	        }
	        return true;
	    }

	    public String nextLine() {
	        tokenizer = new StringTokenizer("");    //清空内存中的字符
	        return innerNextLine();
	    }

	    public void clear() {
	        tokenizer = new StringTokenizer("");
	    }

	    public String next() {
	        hasNext();
	        return tokenizer.nextToken();
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

	    public double nextDouble() {
	        return Double.parseDouble(next());
	    }
	}

}
